home *** CD-ROM | disk | FTP | other *** search
/ Power Bytes: Money & Finance / PowerBytes Money and Finance CD-ROM 01 / PowerBytes Money and Finance CD-ROM 01.iso / Demos / TrueBASIC Demo / Libraries / FnmLib < prev    next >
Encoding:
Text File  |  1985-05-31  |  1.8 KB  |  77 lines  |  [TEXT/TRUE]

  1. !  Library of mathematical functions
  2. !  Copyright (c) 1985 by True BASIC, Inc.
  3.  
  4. EXTERNAL
  5.  
  6. DEF logbase(x,b)                  ! Log to base b
  7.     IF b<=0 or b=1 then
  8.        CAUSE EXCEPTION -3000, "Argument not in range"
  9.     ELSE
  10.        LET logbase = log(x)/log(b)
  11.     END IF
  12. END DEF
  13.  
  14. DEF erf(x)                        ! Error function
  15.     DECLARE DEF norm1
  16.     LET erf = 2*norm1(sqr(2)*x)
  17. END DEF
  18.  
  19. DEF normal(a,b)                   ! Area under normal curve
  20.     DECLARE DEF norm1
  21.     IF a*b<0 then
  22.        LET normal = norm1(a) + norm1(b)
  23.     ELSE
  24.        LET normal = abs(norm1(a) - norm1(b))
  25.     END IF
  26. END DEF
  27.  
  28. DEF norm1(x)                      ! Normal from 0 to x
  29.     LET x1 = abs(x)
  30.     IF x1>5.1 then
  31.        LET norm1 = .5
  32.        EXIT DEF
  33.     END IF
  34.     LET u = x1*x1/2
  35.     LET c = 1/sqr(2*pi)
  36.     LET term, sum = x1
  37.     FOR i = 1 to 45
  38.         LET term = -term * u/i
  39.         LET sum = sum + term/(2*i+1)
  40.     NEXT i
  41.     LET norm1 = c*sum
  42. END DEF
  43.  
  44. DEF factrl(n)                     ! Factorial
  45.     IF n<0 or n<>int(n) then CAUSE EXCEPTION -3000, "Argument not in range"
  46.     LET f = 1
  47.     FOR i = 1 to n
  48.         LET f = f*i
  49.     NEXT i
  50.     LET factrl = f
  51. END DEF
  52.  
  53. DEF binom(n,j)                    ! Binomial coefficient
  54.     IF n<0 or n<>int(n) or j<0 or j<>int(j) then CAUSE EXCEPTION -3000, "Argument not in range"
  55.     IF j>n then
  56.        LET binom = 0
  57.        EXIT DEF
  58.     END IF
  59.     LET j1 = min(j,n-j)
  60.     LET b = 1
  61.     FOR k = 1 to j1
  62.         LET b = b*(n-k+1)/k
  63.     NEXT k
  64.     LET binom = b
  65. END DEF
  66.  
  67. DEF binompr(n,j,p)                ! Binomial distribution
  68.     DECLARE DEF binom
  69.     IF p<0 or p>1 then CAUSE EXCEPTION -3000, "Argument not in range"
  70.     LET binompr = binom(n,j) * p^j * (1-p)^(n-j)
  71. END DEF
  72.  
  73. DEF poisson(m,j)                  ! Poisson distribution
  74.     DECLARE DEF factrl
  75.     LET poisson = exp(-m) * m^j / factrl(j)
  76. END DEF
  77.